Page({
  data:{
   name:'',
   zhanghao:'',
   mima:''
  },
  getName(e){
    console.log("获取用户名",e.detail.value)
    this.setData({
      name:e.detail.value
    })
  },
  getZhangHao(e){
    console.log("获取用户名",e.detail.value)
    this.setData({
      zhanghao:e.detail.value
    })
  },
  getMiMa(e){
    console.log("获取用户名",e.detail.value)
    this.setData({
      mima:e.detail.value
    })
  },
  zhuce(){
    let name=this.data.name
    let zhanghao=this.data.zhanghao 
    let mima=this.data.mima
    console.log("点击了注册")
    console.log('name',name)
    console.log('zhanghao',zhanghao)
    console.log('mima',mima)
  
  if(name.length<2 || name.length>4){
   wx.showToast({
     icon:'none',
     title: '用户名输入错误,请输入正确用户名',
   })
   return
  }
  if(zhanghao.length<6 || zhanghao.length>11){
    wx.showToast({
      icon:'none',
      title: '账号输入错误,请输入正确账号',
    })
    return
   }
   if(mima.length<6 || mima.length>6){
    wx.showToast({
      icon:'none',
      title: '密码输入错误,请输入正确密码',
    })
    return
   }
   wx.cloud.database().collection('user').add({
     data:{
       name:name,
       zhanghao:zhanghao,
       mima:mima
     },
     success(res){
       console.log('注册成功')
       wx.showToast({
         title: '注册成功',
       })
       wx.navigateTo({
         url: '../login/login',
       })
     },
     fail(res){
       console.log('注册失败')
      }
   })
   
  }
})